package org.gap.wizards.world.actions;

import java.awt.Point;
import java.util.List;

import org.gap.wizards.views.MessageOutput;
import org.gap.wizards.world.Location;
import org.gap.wizards.world.WorldAction;

public class LookAction implements WorldAction {

	private final Location map;
	private final MessageOutput output;
	private final TargetSelector selector;

	public LookAction(MessageOutput output, Location map, TargetSelector selector) {
		this.output = output;
		this.map = map;
		this.selector = selector;
	}
	
	@Override
	public void perform() {
		output.addMessage("Where do you wish to look? ");
		Point lookLocation = selector.findTarget(map.getCharacterLocation());

		if (selector.lastKeyPressed() == '\n') {
			List<Object> lookingAt = map.getAllFromLocation(lookLocation);
			if (lookLocation.equals(map.getCharacterLocation())) {
				output.addMessage("You look yourself over");
			}
			if (lookingAt.isEmpty()) {
				output.addMessage("There is nothing to see.");
			} else {
				output.addMessage("You see a " + lookingAt.get(0).toString());
			}
		}
	}

}
